package com.lzb.play.adapter;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lzb.play.R;
import com.lzb.play.basic.ProviderMultiAdapter;
import com.lzb.play.bean.GridBean;

public class GridAdapter extends ProviderMultiAdapter<GridBean> {

    public GridAdapter() {
        addItemProvider(new GridProvider());
    }

    private class GridProvider extends BaseItemProvider<GridBean> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_grid;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, GridBean bean) {
            if (bean.isSetting()) {
                baseViewHolder.setImageResource(R.id.ivGridItemImg, R.drawable.icon_grid_is_set);
                if (bean.isSelected()) {
                    baseViewHolder.getView(R.id.ivGridItemImg).setAlpha(1);
                } else {
                    baseViewHolder.getView(R.id.ivGridItemImg).setAlpha(0.5f);
                }
            } else {
                baseViewHolder.setImageResource(R.id.ivGridItemImg, R.drawable.icon_grid_no_set);
            }
        }
    }

}
